﻿using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;

public class PreBuildProcessing : IPreprocessBuildWithReport
{
    public int callbackOrder => 1;

    public void OnPreprocessBuild(BuildReport report)
    {
#if UNITY_2019 || UNITY_2020
        // https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/blob/main/Design/DevelopmentQAList.md
        // Unity 2020及以前（如2019）版本构建 WebGL 仍然需要 Python2 ，而Mac OS 12.3版本起已经不再内置 Python2。
        // 需要自己安装，这里帮助设置环境变量
        // windows要自己安装和设置环境变量，否则也会有il2cpp not run properly的报错，虽然详细报错信息跟mac不一样
        if (Application.platform == RuntimePlatform.OSXEditor)
            System.Environment.SetEnvironmentVariable("EMSDK_PYTHON",
                "/Library/Frameworks/Python.framework/Versions/2.7/bin/python");
#endif
    }
}